package com.example.dao.daoImple;

import com.example.dao.HistoryDao;
import com.example.entity.History;
import com.example.util.JDBCUtil;

import java.util.List;

public class HistoryDaoImpl implements HistoryDao {
    @Override
    public History isHistory(Long userId, Long typeId, Integer type) {
        String sql = "SELECT user_id,type_id, type FROM tb_views WHERE user_id = ? AND type_id = ? AND type = ?";
        History history = JDBCUtil.getInstance(History.class, sql,userId, typeId, type);
        return history;
    }

    @Override
    public boolean addHistory(History history) {
        String sql = "INSERT INTO tb_views (user_id,type_id,view_time,`type`) VALUES(?,?,NOW(),?)";
        return JDBCUtil.ALLCUD(sql,history.getUserId(),history.getTypeId(),history.getType())>0?true:false;
    }

    @Override
    public int updateTime(Long userId, Long typeId, Integer type) {
        String sql = "UPDATE tb_views SET view_time = NOW() WHERE user_id = ? AND type_id = ?  AND TYPE = ?";
        return JDBCUtil.ALLCUD(sql,userId,typeId,type);
    }
}
